package com.gxp.web.controller.system;

import com.gxp.common.core.controller.BaseController;
import com.gxp.common.core.domain.AjaxResult;
import com.gxp.common.core.page.TableDataInfo;
import com.gxp.system.domain.ZkAudit;
import com.gxp.system.service.IZkAuditService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/system/audit")
public class SysAuditController extends BaseController {

    private String prefix = "system/audit";

    @Autowired
    private IZkAuditService auditService;

    @RequiresPermissions("system:audit:view")
    @GetMapping()
    public String audit()
    {
        return prefix + "/audit";
    }

    @RequiresPermissions("system:audit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZkAudit audit)
    {
        startPage();
        List<ZkAudit> list = auditService.selectZkAuditList(audit);
        return getDataTable(list);
    }

    @RequiresPermissions("system:audit:detail")
    @GetMapping("/detail/{auditId}")
    public String detail(@PathVariable("auditId") Long auditId, ModelMap mmap)
    {
        mmap.put("audit", auditService.selectZkAuditByAuditId(auditId));
        return prefix + "/detail";
    }

    @RequiresRoles("admin")
    @PostMapping("/clean")
    @ResponseBody
    public AjaxResult clean()
    {
        auditService.cleanAudit();
        return success();
    }
}
